<template>
	<div class="g-container">
		<el-form label-width="80px" class="g-form-wraper">
			<el-form-item label="用户名">
				<el-input placeholder="请输入用户名" v-model="user.username" />
			</el-form-item>
			<el-form-item label="密码">
				<el-input placeholder="请输入密码" v-model="user.password" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" class="m-btn" @click="bindLogin">登录</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
import axios from 'axios'
export default {
	data() {
		return {
			user: {
				username: '',
				password: '',
			},
		}
	},
	methods: {
		bindLogin() {
			// 判断用户名和密码
			console.log('username :', this.user.username)
			console.log('password :', this.user.password)
			axios({
				method: 'GET',
				url: 'http://localhost:3000/login',
				params: {
					username: this.user.username,
					password: this.user.password,
				},
			})
				.then(res => {
					console.log('res ', res)
                    if(res.data.code == 1){
                        this.$router.push({ path: '/home' })
                    }else{
                        this.$message.error(res.data.message)
                    }
					
				})
				.catch(err => {
					console.log('err ', err)
				})
		},
	},
}
</script>

<style lang="css" scoped>
.g-container {
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #2b3c4d;
	height: 100vh;
}
.g-form-wraper {
	width: 500px;
	background-color: #ffffff;
	padding: 40px;
}

.m-btn {
	width: 80%;
}
</style>
